<template>
  <div>
    <!-- 列表 -->
    <el-table :data="menulist" style="width: 100%" row-key="id" border lazy
      :tree-props="{ children: 'children' }" default-expand-all>
      <el-table-column prop="id" label="菜单编号" width="80">
      </el-table-column>
      <el-table-column prop="title" label="菜单名称">
      </el-table-column>
      <el-table-column prop="pid" label="上传菜单" width="80">
      </el-table-column>
      <el-table-column prop="icon" label="菜单图标">
        <template v-slot="title">
          <!-- 图标 -->
          <i :class="title.row.icon"></i>
        </template>
      </el-table-column>
      <el-table-column prop="url" label="菜单地址">

      </el-table-column>
      <el-table-column prop="status" label="状态">
        <!-- <el-button size="mini" type="success" plain>启用</el-button> -->
        <template slot-scope="item">
          <div>
            {{ item.row.status == 1 ? '开启' : '禁用' }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="item">
          <div>
            <el-button size="mini" type="primary" @click="edit(item.row.id)">编辑</el-button>
            <el-button size="mini" type="danger" @click="del(item.row.id)">删除</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
//引入封装好的接口
// import {getMenuList} from '../../request/api'
import { mapGetters, mapActions } from 'vuex';
import { menuDel } from '../../request/api'
export default {
  data() {
    return {

    };
  },
  computed: {
    ...mapGetters({
      menulist: 'menu/getMenu'
    })
  },
  mounted() {
    this.getMenuAction()
    console.log(this.menulist);
  },
  methods: {
    ...mapActions({
      getMenuAction: 'menu/getMenuAction'
    }),
    edit(id) {
      this.$emit('edit',id)
    },
    // 删除
    del(id) {
      // console.log('shan');
      this.$confirm('确定删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // 删除接口
        menuDel({ id }).then(res => {
          if(res.code==200){
            this.$message.success(res.msg)
            // 重新触发行动
            this.getMenuAction()
          }else{
            this.$message.error(res.msg)
          }
            // console.log(res, '删除');
          })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    }
  }
}
</script>
<style lang="">
    
</style>